package cn.wgx.module.file.config;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 七牛云配置
 */
@Configuration
public class QiniuOSSConfig {

	
	@Value("${qiniu.oss.access-key:xxxxx}")
	private String accessKeyId;
	@Value("${qiniu.oss.accessKeySecret:xxxxx}")
	private String accessKeySecret;
    @Value("${qiniu.oss.endpoint:xxxxx}")
    private String endpoint;
    @Value("${qiniu.oss.bucketName:xxxxx}")
    private String bucketName;
	 
	 /**
     * 机房选择
      * 机房	Region
      * 华东	Region.region0(), Region.huadong()
      * 华北	Region.region1(), Region.huabei()
      * 华南	Region.region2(), Region.huanan()
      * 北美	Region.regionNa0(), Region.beimei()
      * 东南亚 Region.regionAs0(), Region.xinjiapo()
     */
    @Bean
    public com.qiniu.storage.Configuration qiniuConfig() {
        return new com.qiniu.storage.Configuration(Region.huabei());
    }
    /**
     * 构建一个七牛上传工具实例
     */
    @Bean
    public UploadManager uploadManager() {
        return new UploadManager(qiniuConfig());
    }

 

    /**
     * 认证信息实例
     * @return
     */
    @Bean
    public Auth auth() {
        return Auth.create(accessKeyId, accessKeySecret);
    }
    
    /**
     * 构建七牛空间管理实例
     */
    @Bean
    public BucketManager bucketManager() {
        return new BucketManager(auth(), qiniuConfig());
    }

}
